using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using T2.WebSecurity.Business;
using T2.WebSecurity.ASPMVC.Entity;
using T2.WebSecurity.ASPMVC.Entity.Interface;
using T2.WebSecurity.ASPMVC.Entity.Search;
using T2.WebSecurity.ASPMVC.Entity.Search.Interface;
using T2.WebSecurity.Business.Entities;
using T2.WebSecurity.Business.Entities.Interfaces;
using T2.WebSecurity.ASPMVC.Entity.Translators;
using T2.WebSecurity.Business.Entities.Search.Interfaces;
using T2.WebSecurity.Business.Entities.Search;
using T2.WebSecurity.ASPMVC.ViewModel;
using System.Web.Http;
using System.Net.Http;
using System.Net;

namespace T2.WebSecurity.ASPMVC.Controllers
{
    public partial class UserProfileDataAPIController : ApiController
    {
        [System.Web.Http.Authorize(Roles = "super admin, application admin, admin")]    
        public HttpResponseMessage PostUserProfileData(UserProfileData_ui param)
        {
            if (User.IsInRole("admin") && (param.Action.Equals("Edit") || param.Action.Equals("Delete")))
            {
                HttpResponseMessage message = new HttpResponseMessage();
                message.ReasonPhrase = "Unauthorized for admins. Did not save";
                message.StatusCode = HttpStatusCode.Unauthorized;
                return message;
            }
            try
            {
                UserProfileDataViewModel model = new UserProfileDataViewModel(false);
                Int32 retVal = model.Set(param);
                if (retVal == 1)
                {
                    HttpResponseMessage message = new HttpResponseMessage();
                    message.ReasonPhrase = "Completed saving UserProfileData";
                    message.StatusCode = HttpStatusCode.OK;
                    return message;
                }
                else
                {
                    HttpResponseMessage message = new HttpResponseMessage();
                    message.ReasonPhrase = "UserProfileData did not save";
                    message.StatusCode = HttpStatusCode.NotAcceptable;
                    return message;
                }
            }
            catch (Exception ex)
            {
                HttpResponseMessage message = new HttpResponseMessage();
                message.ReasonPhrase = ex.Message;
                message.StatusCode = HttpStatusCode.InternalServerError;
                return message;
            }
        }

        [System.Web.Http.Authorize(Roles = "super admin, application admin, admin, user")] 
		public List<IUserProfileData_ui> GetUserProfileData(UserProfileData_ui param)
        {
            if (User.IsInRole("admin"))
            {
                // only admin created roles

            }
            if (User.IsInRole("user"))
            {
                // only user in roles GetRoles

            }
            try
            {
                UserProfileDataViewModel model = new UserProfileDataViewModel(false);
                List<IUserProfileData_ui> retVal = model.ModelList(param);
                return retVal;
            }
            catch (Exception ex)
            {
                HttpResponseMessage message = new HttpResponseMessage();
                message.ReasonPhrase = ex.Message;
                message.StatusCode = HttpStatusCode.InternalServerError;
                throw new HttpResponseException(message);  
            }
        }

        [System.Web.Http.Authorize(Roles = "super admin, application admin, admin, user")] 
		public List<IUserProfileData_ui> GetUserProfileDataSearch(UserProfileDataSearch_ui param)
        {
            if (User.IsInRole("admin"))
            {
                // only admin created roles

            }
            if (User.IsInRole("user"))
            {
                // only user in roles GetRoles

            }
            try
            {
                UserProfileDataViewModel model = new UserProfileDataViewModel(false);
                List<IUserProfileData_ui> retVal = model.SearchList(param);
                return retVal;
            }
            catch (Exception ex)
            {
                HttpResponseMessage message = new HttpResponseMessage();
                message.ReasonPhrase = ex.Message;
                message.StatusCode = HttpStatusCode.InternalServerError;
                throw new HttpResponseException(message);  
            }
        }	


    }
}